package com.example.myservice;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener {
	Button btn_start_service, btn_stop_service;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
		initEvent();
	}

	private void initEvent() {
		// TODO Auto-generated method stub
		btn_start_service.setOnClickListener(this);
		btn_stop_service.setOnClickListener(this);
	}

	private void initView() {
		// TODO Auto-generated method stub
		btn_start_service = (Button) findViewById(R.id.btn_start_service);
		btn_stop_service = (Button) findViewById(R.id.btn_stop_service);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btn_start_service:
			startMyservice();
			break;
		case R.id.btn_stop_service:
			stopMyservice();
			break;

		default:
			break;
		}
	}

	private void stopMyservice() {
		// TODO Auto-generated method stub
		Intent in = new Intent();
		in.setAction("com.pxxy.myservice");
		stopService(in);
		Log.d("myservice", "stopMyservice");
	}

	private void startMyservice() {
		// TODO Auto-generated method stub
		Intent in = new Intent();
		in.setAction("com.pxxy.myservice");
		startService(in);
		Log.d("myservice", "startMyservice");
	}

}
